var app = getApp()
import {
	store,
	mutations
} from '@/uni_modules/uni-id-pages/common/store.js'

const stat = {
	data:{
		shopLoaded:false
	},
	computed:{
			userInfo() {
				return store.userInfo
			}
		},
		methods:{
			async getShop() {
				let res = await uniCloud.databaseForJQL().collection("zgj-shop")
					.where('user_id=="' + this.userInfo._id + '"')
					.get()
				console.log("cloud res", res)
				if (res.errCode !== 0) {					
					return null
				}
				return res.data.length > 0 ? res.data[0] : null
			},
			async statTel(statObj){
				if(this.userInfo && this.userInfo._id){
					statObj.user_id = this.userInfo._id
					if(app.globalData.shop){
						statObj.shop_name = app.globalData.shop.name
					}
					else if(!this.shopLoaded){
						var shop =await this.getShop()
						this.shopLoaded = true
						if(shop){
							app.globalData.shop = shop
							statObj.shop_name = shop.name
						}
					}
				}
				console.log("statTel",statObj)
				this.$http.post('/web/ai/stat/phonecall',statObj,(res)=>{
					
				})
			}
		}
}
export default stat